package model

import (
	"gorm.io/gorm"
	"time"
	"wechat-moments_0926/config"
)

type Feed struct {
	Id        uint32         `gorm:"column:id;type:int UNSIGNED;comment:id;primaryKey;not null;" json:"id"`                 // id
	UserId    int32          `gorm:"column:user_id;type:int;comment:作者(用户ID);not null;" json:"user_id"`                     // 作者(用户ID)
	Image     string         `gorm:"column:image;type:varchar(300);comment:图片;default:NULL;" json:"image"`                  // 图片
	Text      string         `gorm:"column:text;type:varchar(300);comment:文字;default:NULL;" json:"text"`                    // 文字
	Status    int8           `gorm:"column:status;type:tinyint(1);comment:状态: 1:公开 2:私密;not null;default:0;" json:"status"` // 状态: 1:公开 2:私密
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (f *Feed) TableName() string {
	return "feed"
}

// 动态发布
func (f *Feed) AddFeed() error {
	return config.DB.Create(&f).Error
}

func (f *Feed) FindFeed() (list []Feed, err error) {
	err = config.DB.Where("status = 1 ").Find(list).Error
	return
}
